package com.tledu.email.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tledu.common.annotation.Log;
import com.tledu.common.core.controller.BaseController;
import com.tledu.common.core.domain.AjaxResult;
import com.tledu.common.enums.BusinessType;
import com.tledu.email.domain.EmailTableOutbox;
import com.tledu.email.service.IEmailTableOutboxService;
import com.tledu.common.utils.poi.ExcelUtil;
import com.tledu.common.core.page.TableDataInfo;

/**
 * 邮箱发件箱Controller
 * 
 * @author ruoyi
 * @date 2024-08-29
 */
@RestController
@RequestMapping("/email/outbox")
public class EmailTableOutboxController extends BaseController
{
    @Autowired
    private IEmailTableOutboxService emailTableOutboxService;

    // 逻辑删除用户发件箱的内容，实际上是进行更新操作
    @PreAuthorize("@ss.hasPermi('email:outbox:edit')")
    @Log(title = "逻辑删除用户发件箱的内容", businessType = BusinessType.UPDATE)
    @PutMapping("/update/{ids}")
    public AjaxResult updateSymbol(@PathVariable Long[] ids)
    {
        return toAjax(emailTableOutboxService.updateSymbol(ids));
    }

    // condtion
    // 根据条件动态查询当前用户发件箱的信息
    @PreAuthorize("@ss.hasPermi('email:outbox:list')")
    @GetMapping("/condition")
    public TableDataInfo selectByCondition(EmailTableOutbox emailTableOutbox)
    {
        startPage();
        List<EmailTableOutbox> list = emailTableOutboxService.selectByCondition(emailTableOutbox);
        return getDataTable(list);
    }

    // 查询当前用户发件箱的信息
    @PreAuthorize("@ss.hasPermi('email:outbox:list')")
    @GetMapping("/sendList")
    public TableDataInfo sendList(EmailTableOutbox emailTableOutbox)
    {
        startPage();
        List<EmailTableOutbox> list = emailTableOutboxService.sendList(emailTableOutbox);
        return getDataTable(list);
    }

    /**
     * 查询邮箱发件箱列表
     */
    @PreAuthorize("@ss.hasPermi('email:outbox:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmailTableOutbox emailTableOutbox)
    {
        startPage();
        List<EmailTableOutbox> list = emailTableOutboxService.selectEmailTableOutboxList(emailTableOutbox);
        return getDataTable(list);
    }

    /**
     * 导出邮箱发件箱列表
     */
    @PreAuthorize("@ss.hasPermi('email:outbox:export')")
    @Log(title = "邮箱发件箱", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmailTableOutbox emailTableOutbox)
    {
        List<EmailTableOutbox> list = emailTableOutboxService.selectEmailTableOutboxList(emailTableOutbox);
        ExcelUtil<EmailTableOutbox> util = new ExcelUtil<EmailTableOutbox>(EmailTableOutbox.class);
        util.exportExcel(response, list, "邮箱发件箱数据");
    }

    /**
     * 获取邮箱发件箱详细信息
     */
    @PreAuthorize("@ss.hasPermi('email:outbox:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(emailTableOutboxService.selectEmailTableOutboxById(id));
    }

    /**
     * 新增邮箱发件箱
     */
    @PreAuthorize("@ss.hasPermi('email:outbox:add')")
    @Log(title = "邮箱发件箱", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmailTableOutbox emailTableOutbox)
    {
        return toAjax(emailTableOutboxService.insertEmailTableOutbox(emailTableOutbox));
    }

    /**
     * 修改邮箱发件箱
     */
    @PreAuthorize("@ss.hasPermi('email:outbox:edit')")
    @Log(title = "邮箱发件箱", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmailTableOutbox emailTableOutbox)
    {
        return toAjax(emailTableOutboxService.updateEmailTableOutbox(emailTableOutbox));
    }

    /**
     * 删除邮箱发件箱
     */
    @PreAuthorize("@ss.hasPermi('email:outbox:remove')")
    @Log(title = "邮箱发件箱", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(emailTableOutboxService.deleteEmailTableOutboxByIds(ids));
    }
}
